package com.longlong.bean;


import lombok.Getter;

import java.io.Serializable;
import java.util.HashMap;


@Getter

public class AccessTokenGzhBean implements Serializable {

    /*
    * grant_type,固定值
    * */
    private static String grant_type = "client_credential";

    /*
     * appId 公众号的唯一识别码
     * */
    private String appid;

    /*
     * secret 公众号的唯一凭证密钥
     * */
    private String secret;
    /*
     * accessToken 获取token
     * */
    private String accessToken;

    /*
     * expiresTime token过期时间
     * */
    private long expiresTime;

    public AccessTokenGzhBean(String appid, String secret, String accessToken, long expiresTime) {
        this.appid = appid;
        this.secret = secret;
        this.accessToken = accessToken;
        if(expiresTime > 0){
            this.expiresTime = System.currentTimeMillis() + expiresTime *1000;
        }
    }


    /*
    * 构建获取access token请求对象
    *
    * */
    public static HashMap<String, String> requestOf(String appid,String secret){
        HashMap<String, String> request = new HashMap<>(16);
        request.put("appid",appid);
        request.put("secret",secret);
        request.put("grant_type","client_credential");
        return request;
    }

    /*
    * 判断token是否失效
    * */
    public static AccessTokenGzhBean responseOf(String accessToken,long expiresTime){
        return new AccessTokenGzhBean("","",accessToken,expiresTime);
    }


    public boolean isExpired(){
        return System.currentTimeMillis() > expiresTime;
    }

































}
